package com.tensquare.qa.controller;

import com.tensquare.qa.client.LabelClient;
import com.tensquare.qa.pojo.Problem;
import com.tensquare.qa.service.ProblemService;
import entity.PageResult;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by WF on 2019/9/18 10:51
 */
@RestController
@RequestMapping("problem")
public class ProblemController {

    @Autowired
    private ProblemService problemService;
    @Autowired
    private LabelClient labelClient;
    //1.查询最新问题列表
    @GetMapping("newlist/{labelid}/{page}/{size}")
    public Result newList(@PathVariable String labelid,@PathVariable int page,@PathVariable int size){
        //1.1)查询出最新问题列表
        PageResult<Problem> problems = problemService.findnewList(labelid,page,size);
        //1.2)返回
        return new Result(true,StatusCode.OK,"查询最新问题列表成功！",problems);
    }
    //2.查询另一个微服务tensquare-base的findById（）方法
    @GetMapping("/label/{labelId}")
    public Result findById(@PathVariable("labelId") String labelId){
        return labelClient.findById(labelId);
    }
}
